package controllers;

import java.io.IOException;
import java.lang.reflect.Type;

import play.db.jpa.GenericModel.JPAQuery;

import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;

import models.User;

public class Users extends CRUD {
	
	public static void listAllJson(){
		renderJSON(User.findAll());
	}

	public static void filterJson(String q, Integer limit){
		
		JPAQuery query = User.find("lower(username) like ?1 or lower(firstName) like ?1 or lower(lastName) like ?1 order by lower(lastName), lower(firstName)", "%"+q.toLowerCase()+"%");
		if(limit != null){
			renderJSON(query.fetch(limit));
		}else{
			renderJSON(query.fetch());
		}
	}
}
